home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 18
/
CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso
/
CUCD
/
Graphics
/
DrawStudio
/
Table.dsrx
< prev
next >
Wrap
Text File
|
1997-09-12
|
13KB
|
486 lines
/* Allow commands to return results */
options results
/* On error, goto ERROR:. Comment out this line if you wish to */
/* perform your own error checking. */
signal on error
'PROJECT_LOCK'
/* BEGIN PROGRAM *************************************************/
/* +++++++++++++++++++++++++++ */
/* + + */
/* + Table ARexx script V1.0 + */
/* + + */
/* + Written by Andrew Elia + */
/* + + */
/* +++++++++++++++++++++++++++ */
PTCNV = 28.346 /* *CONSTANT!* Converts points to Centimetres */
DATAFILE = "Dh0:T/DSMiscRexxVol3/TableDataFile" /* Full path of data file */
CELLLEFTMARGIN = 0.25 /* Sets left margin inside cell */
CELLRIGHTMARGIN = 0.25 /* Sets right margin inside cell */
CELLTOPMARGIN = 0.25 /* Sets top margin inside cell */
CELLBOTTOMMARGIN = 0.25 /* Sets bottom margin inside cell */
EVENWIDTH = 0 /* Ensures that all cells are the same width */
EVENHEIGHT = 1 /* Ensures that all cells are the same height */
CENTRETALLEST = 1 /* Sets vertical alignment method (0 for individual centre, 1 for tallest in row, 2 for tallest in table) */
SHOWMARGINS = 1 /* Set to 1 to show margins, 0 to hide them */
XOFFSET=2 /* Sets the offset between the left of the table and the page*/
YOFFSET=2 /* Sets the offset between the top of the table and the page */
UNIT="cm" /* Sets the default unit */
/* Open data file */
OK = Open('File',DATAFILE,'r')
If OK = 0 Then Do
REQ_MESSAGE TEXT '"Error: Unable to open data file"' '"Cancel"'
PROJECT_UNLOCK
Exit
End
/* Read in data */
LINES = 0
FINISHED = 0
do while ((~eof('File')) & (FINISHED = 0))
INPUT = readln('File')
IF INPUT = "" Then Do
FINISHED = 1
End
Else Do
FILEDATA.LINES = INPUT
LINES = LINES + 1
End
End
Call Close('File')
CELLSX = 0
CELLSY = LINES
/* This bit works out the number of columns from the amount of data */
/* in the file */
Do N = 0 To LINES - 1
TEMPSTR = Compress(FILEDATA.N, ',')
NUMDAT = Length(FILEDATA.N) - Length(TEMPSTR)
If NUMDAT > CELLSX Then Do
CELLSX = NUMDAT
End
End
CELLSX = CELLSX + 1
/* This bit sifts through the data to extract any control codes */
/* and also sorts the data into a more convenient format */
Do N = 0 To LINES - 1
TEMPSTR = Compress(FILEDATA.N, ',')
NUMDAT = Length(FILEDATA.N) - Length(TEMPSTR)
START = 1
Do M = 0 To NUMDAT-1
POS = Index(FILEDATA.N, ',', START)
DATA.N.M = Substr(FILEDATA.N, START, POS - START)
If Length(DATA.N.M) > 2 Then Do
JUST.N.M = Substr(DATA.N.M, 1, 2)
DATA.N.M = Substr(DATA.N.M, 3, Length(DATA.N.M) - 2)
End
START = POS + 1
End
DATA.N.NUMDAT = Substr(FILEDATA.N, START, Length(FILEDATA.N) - START + 1)
If Length(DATA.N.NUMDAT) > 2 Then Do
JUST.N.NUMDAT = Upper(Substr(DATA.N.NUMDAT, 1, 2))
DATA.N.NUMDAT = Substr(DATA.N.NUMDAT, 3, Length(DATA.N.NUMDAT) - 2)
End
End
/* I added this bit as a safety measure. If the horizontal or vertical */
/* justify codes are either absent or wrongly specified (they are case */
/* insensitive, by the way), this part will display a requester asking */
/* whether or not the operation should proceed or not despite the */
/* problem. In the long run, it saves a great deal of hair loss! It */
/* should be noted that the following is programmed so that you can */
/* leave some cells totally blank without it complaining. */
JUMPNOW = 0
Do X = 0 To CELLSX-1
Do Y = 0 To CELLSY-1
HOK = 0
VOK = 0
If Left(JUST.Y.X, 1) = "L" Then Do
HOK = 1
End
If Left(JUST.Y.X, 1) = "C" Then Do
HOK = 1
End
If Left(JUST.Y.X, 1) = "R" Then Do
HOK = 1
End
If Right(JUST.Y.X, 1) = "T" Then Do
VOK = 1
End
If Right(JUST.Y.X, 1) = "M" Then Do
VOK = 1
End
If Right(JUST.Y.X, 1) = "B" Then Do
VOK = 1
End
If DATA.Y.X = "" Then Do
HOK = 1
VOK = 1
End
If (HOK = 0) | (VOK = 0) Then Do
REQ_MESSAGE TEXT '"Error: The data file contains invalid control codes.*nThis may cause the table to be drawn incorrectly."' '"Proceed|Cancel"'
If Result = 1 Then Do
JUMPNOW = 1
Leave
End
Else Do
PROJECT_UNLOCK
Exit
End
End
End
If JUMPNOW = 1 Then Do
Leave
End
End
REDRAW_OFF
BIGWIDEST = 0
/* Here we do several things: First we look for any instances of "\n" in */
/* the data, and convert them into carriage returns. We also look for the */
/* widest text (and therefore cells) in the table and in each column. This */
/* will be of use when we are applying even cell widths. Finally, we */
/* quietly print out all of the text from the table and make a note of the */
/* name DrawStudio has given them for future reference */
Do X = 0 To CELLSX-1
WIDEST.X = 0
Do Y = 0 To CELLSY-1
TRYSL = 0
Do While TRYSL = 0
SLPOS = Index(DATA.Y.X, '\n')
If SLPOS = 0 Then Do
TRYSL = 1
End
Else Do
DATA.Y.X = Left(DATA.Y.X, SLPOS - 1)||'0D'x||Right(DATA.Y.X, Length(DATA.Y.X) - SLPOS - 1)
End
End
MYJUST = "Left"
If Left(JUST.Y.X, 1) = "L" Then Do
MYJUST = "Left"
End
If Left(JUST.Y.X, 1) = "C" Then Do
MYJUST = "Centre"
End
If Left(JUST.Y.X, 1) = "R" Then Do
MYJUST = "Right"
End
'CREATE_TEXT '||XOFFSET||UNIT||' '||YOFFSET||UNIT||' "'||DATA.Y.X||'"'
TEXT.Y.X = Result
'ATTRS_TEXT_SET FONT "Times-Roman" SIZE "12" ALIGN "'||MYJUST||'"'
OBJECT_SPECS_GET STEM 'OBJSPECS.'
MYWIDTH = OBJSPECS.WIDTH / PTCNV
If MYWIDTH > WIDEST.X Then Do
WIDEST.X = MYWIDTH
End
End
If WIDEST.X > BIGWIDEST Then Do
BIGWIDEST = WIDEST.X
End
End
BIGTALLEST = 0
/* Below, we find the tallest cells in each row as well as in the entire */
/* table. */
Do Y = 0 To CELLSY-1
TALLEST.Y = 0
Do X = 0 To CELLSX-1
OBJECT_DESELECT
OBJECT_SELECT TEXT.Y.X
OBJECT_SPECS_GET STEM 'OBJSPECS.'
MYHEIGHT = OBJSPECS.HEIGHT / PTCNV
If MYHEIGHT > TALLEST.Y Then Do
TALLEST.Y = MYHEIGHT
End
End
If TALLEST.Y > BIGTALLEST Then Do
BIGTALLEST = TALLEST.Y
End
End
/* From the above calculations, we can now work out the exact dimensions */
/* of the entire table. We'll need this for ruling the table's lines */
If EVENWIDTH = 1 Then Do
TABLEWIDTH = (CELLLEFTMARGIN + CELLRIGHTMARGIN + BIGWIDEST) * CELLSX
End
Else Do
TABLEWIDTH = 0
Do X = 0 To CELLSX-1
TABLEWIDTH = TABLEWIDTH + CELLLEFTMARGIN + CELLRIGHTMARGIN + WIDEST.X
End
End
If EVENHEIGHT = 1 Then Do
TABLEHEIGHT = (CELLTOPMARGIN + CELLBOTTOMMARGIN + BIGTALLEST) * CELLSY
End
Else Do
TABLEHEIGHT = 0
Do Y = 0 To CELLSY-1
TABLEHEIGHT = TABLEHEIGHT + CELLTOPMARGIN + CELLBOTTOMMARGIN + TALLEST.Y
End
End
LINESGROUPNUM = 0
MARGINLINESGROUPNUM = 0
/* Now for the graph bit: For the horizontal section, we simply rule a line */
/* downwards, and start aligning all the table text horizontally. Much of */
/* this will depend upon what control codes have been set in the data file. */
X1 = XOFFSET
Y1 = YOFFSET
Y2 = Y1 + TABLEHEIGHT
Do X = 0 To CELLSX-1
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X1||UNIT||" "||Y2||UNIT
LINESGROUPNAME.LINESGROUPNUM = Result
LINESGROUPNUM = LINESGROUPNUM + 1
If EVENWIDTH = 1 Then Do
MYWIDTH = BIGWIDEST
End
Else Do
MYWIDTH = WIDEST.X
End
RX1 = X1 + CELLLEFTMARGIN
RX2 = RX1 + MYWIDTH
If SHOWMARGINS = 1 Then Do
CREATE_LINE RX1||UNIT||" "||Y1||UNIT||" "||RX1||UNIT||" "||Y2||UNIT
MARGINLINESGROUPNAME.MARGINLINESGROUPNUM = Result
MARGINLINESGROUPNUM = MARGINLINESGROUPNUM + 1
CREATE_LINE RX2||UNIT||" "||Y1||UNIT||" "||RX2||UNIT||" "||Y2||UNIT
MARGINLINESGROUPNAME.MARGINLINESGROUPNUM = Result
MARGINLINESGROUPNUM = MARGINLINESGROUPNUM + 1
End
Do Y = 0 To CELLSY-1
OBJECT_DESELECT
OBJECT_SELECT TEXT.Y.X
If Left(JUST.Y.X, 1) = "L" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TX = OBJSPECS.LEFT / PTCNV
"OBJECT_MOVE X "||(RX1-TX)||UNIT
End
If Left(JUST.Y.X, 1) = "C" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TX = OBJSPECS.LEFT / PTCNV
WX = OBJSPECS.WIDTH / PTCNV
"OBJECT_MOVE X "||((RX1-TX) + ((MYWIDTH-WX)/2))||UNIT
End
If Left(JUST.Y.X, 1) = "R" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TX = OBJSPECS.LEFT / PTCNV
WX = OBJSPECS.WIDTH / PTCNV
"OBJECT_MOVE X "||((RX1-TX) + (MYWIDTH-WX))||UNIT
End
End
X1 = X1 + CELLLEFTMARGIN + CELLRIGHTMARGIN + MYWIDTH
End
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X1||UNIT||" "||Y2||UNIT
LINESGROUPNAME.LINESGROUPNUM = Result
LINESGROUPNUM = LINESGROUPNUM + 1
/* For the vertical section, we now rule a line across, and start aligning */
/* (or at least trying to) all the table text vertically. Much of this will */
/* depend upon what control codes have been set in the data file, together */
/* with the value of the CENTRETALLEST variable. */
X1 = XOFFSET
Y1 = YOFFSET
X2 = X1 + TABLEWIDTH
Do Y = 0 To CELLSY-1
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y1||UNIT
LINESGROUPNAME.LINESGROUPNUM = Result
LINESGROUPNUM = LINESGROUPNUM + 1
If EVENHEIGHT = 1 Then Do
MYHEIGHT = BIGTALLEST
End
Else Do
MYHEIGHT = TALLEST.Y
End
RY1 = Y1 + CELLTOPMARGIN
RY2 = RY1 + MYHEIGHT
If SHOWMARGINS = 1 Then Do
CREATE_LINE X1||UNIT||" "||RY1||UNIT||" "||X2||UNIT||" "||RY1||UNIT
MARGINLINESGROUPNAME.MARGINLINESGROUPNUM = Result
MARGINLINESGROUPNUM = MARGINLINESGROUPNUM + 1
CREATE_LINE X1||UNIT||" "||RY2||UNIT||" "||X2||UNIT||" "||RY2||UNIT
MARGINLINESGROUPNAME.MARGINLINESGROUPNUM = Result
MARGINLINESGROUPNUM = MARGINLINESGROUPNUM + 1
End
Do X = 0 To CELLSX-1
OBJECT_DESELECT
OBJECT_SELECT TEXT.Y.X
If Right(JUST.Y.X, 1) = "T" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TY = OBJSPECS.TOP / PTCNV
HY = OBJSPECS.HEIGHT / PTCNV
If CENTRETALLEST = 1 Then Do
TY = TY - (TALLEST.Y - HY)
End
If CENTRETALLEST = 2 Then Do
TY = TY - (BIGTALLEST - HY)
End
"OBJECT_MOVE Y "||(RY1-TY)||UNIT
End
If Right(JUST.Y.X, 1) = "M" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TY = OBJSPECS.TOP / PTCNV
If CENTRETALLEST = 0 Then Do
HY = OBJSPECS.HEIGHT / PTCNV
End
If CENTRETALLEST = 1 Then Do
HY = TALLEST.Y
End
If CENTRETALLEST = 2 Then Do
HY = BIGTALLEST
End
"OBJECT_MOVE Y "||((RY1-TY) + ((MYHEIGHT-HY)/2))||UNIT
End
If Right(JUST.Y.X, 1) = "B" Then Do
OBJECT_SPECS_GET STEM 'OBJSPECS.'
TY = OBJSPECS.TOP / PTCNV
HY = OBJSPECS.HEIGHT / PTCNV
If CENTRETALLEST = 1 Then Do
TY = TY + (TALLEST.Y - HY)
End
If CENTRETALLEST = 2 Then Do
TY = TY + (BIGTALLEST - HY)
End
"OBJECT_MOVE Y "||((RY1-TY) + (MYHEIGHT-HY))||UNIT
End
End
Y1 = Y1 + CELLTOPMARGIN + CELLBOTTOMMARGIN + MYHEIGHT
End
CREATE_LINE X1||UNIT||" "||Y1||UNIT||" "||X2||UNIT||" "||Y1||UNIT
LINESGROUPNAME.LINESGROUPNUM = Result
LINESGROUPNUM = LINESGROUPNUM + 1
/* Finally, we group together all the gridlines so that it will make them */
/* a little easier to colour. If SHOWMARGINS is set, then they too will */
/* be grouped, but separately. */
OBJECT_DESELECT
Do N = 0 To LINESGROUPNUM-1
OBJECT_SELECT LINESGROUPNAME.N
End
OBJECT_GROUP
If SHOWMARGINS = 1 Then Do
OBJECT_DESELECT
Do N = 0 To MARGINLINESGROUPNUM-1
OBJECT_SELECT MARGINLINESGROUPNAME.N
End
OBJECT_GROUP
End
REDRAW_ON
/* END PROGRAM ***************************************************/
'PROJECT_UNLOCK'
exit
/* On ERROR */
ERROR:
'PROJECT_UNLOCK'
/* If we get here, either an error occurred with the command's */
/* execution or there was an error with the command itself. */
/* In the former case, rc2 contains the error message and in */
/* the latter, rc2 contains an error number. SIGL contains */
/* the line number of the command which caused the jump */
/* to ERROR: */
if datatype(rc2,'NUMERIC') == 1 then do
/* See if we can describe the error with a string */
select
when rc2 == 103 then
err_string = "ERROR 103, "||,
"out of memory at line "||SIGL
when rc2 == 114 then
err_string = "ERROR 114, "||,
"bad command template at line "||SIGL
when rc2 == 115 then
err_string = "ERROR 115, "||,
"bad number for /N argument at line "||SIGL
when rc2 == 116 then
err_string = "ERROR 116, "||,
"required argument missing at line "||SIGL
when rc2 == 117 then
err_string = "ERROR 117, "||,
"value after keywork missing at line "||SIGL
when rc2 == 118 then
err_string = "ERROR 118, "||,
"wrong number of arguments at line "||SIGL
when rc2 == 119 then
err_string = "ERROR 119, "||,
"unmatched quotes at line "||SIGL
when rc2 == 120 then
err_string = "ERROR 120, "||,
"line too long at line "||SIGL
when rc2 == 236 then
err_string = "ERROR 236, "||,
"unknown command at line "||SIGL
otherwise
err_string = "ERROR "||rc2||", at line "||SIGL
end
end
else if rc2 == 'RC2' then do
err_string = "ERROR in command at line "||SIGL
end
else do
err_string = rc2||", line "||SIGL
end
req_message TEXT '"'err_string'"'
exit